//
// Created by Administrator on 2022/1/31.
//

#ifndef CPP_LEARNING_LEETCODE_JIANZHI05_H
#define CPP_LEARNING_LEETCODE_JIANZHI05_H
#include <string>
#include <iostream>
using namespace std;
class Solution_Jianzhi05 {
public:
    int countSpaceNum(string& s){
        int num = 0;
        for(int i=0;i<s.size();i++){
            if(s[i] == ' '){
                ++num;
            }
        }
        return num;
    }
    string replaceSpace(string s) {
        int spaceNum = countSpaceNum(s);
        string new_s(s.size() + 2*spaceNum,0);
        int i= s.size()-1;
        int j = new_s.size()-1;

        while (i >= 0 && j >= 0){
            if(s[i] != ' '){
                new_s[j--] = s[i--];
            }else{
                new_s[j--] = '0';
                new_s[j--] = '2';
                new_s[j--] = '%';
                i--;
            }
        }
        return new_s;
    }
};

void test_Jianzhi05(){
    Solution_Jianzhi05 s;
    string str = s.replaceSpace("hello world ! !");
    cout<<str<<endl;
}

#endif //CPP_LEARNING_LEETCODE_JIANZHI05_H
